/**
 *  根据用户编号查询电子发票信息
 * @author litao
 */
// import { baseUrl } from '../url'
// import { RequestOptions,  request31 } from "../request1";
// import {ZwPjdyxx} from "../tables/ZwPjdyxx"

// interface Required {
// 	param: Object
// 	pagination: Object
// }
// export function getDzfpByYhbh(options:RequestOptions<Required,ZwPjdyxx[]>){
// 	request31<Required,ZwPjdyxx[]>(Object.assign(options, {url:baseUrl+"/psdmsdfzw/sfglschema/ZwLjfysmx/getDzfpByYhbh"}))
// }

import { baseUrl } from '../url'
import { RequestOptions } from "../request1";
import {ZwPjdyxx} from "../tables/ZwPjdyxx"
interface Required {
	param: Object
	pagination: Object
}
interface  ReturnResult<T>{
	total:number // 总条数
	data:T[] // 内容list
}
export function getDzfpByYhbh(options:RequestOptions<Required, ReturnResult<ZwPjdyxx>>){
	doRequest<Required,ReturnResult<ZwPjdyxx>>(Object.assign(options, {url:baseUrl+"/psdmsdfzw/sfglschema/ZwLjfysmx/getDzfpByYhbh"}))
}

interface PsdResult<T> {
	code : number
	message ?: string
	content ?: T
	pagination:{
		total: number
	}
}
function doRequest<T, R>(options : RequestOptions<T, R>) {
	let Logintoken = uni.getStorageSync("Logintoken")
	uni.request({
		url: options.url,
		method: options.method ?? 'POST',
		dataType: 'json',
		timeout: 10000,
		header: { "Logintoken": Logintoken },
		data: options?.data,
		success: (res) => {
			if (res.statusCode == 200) {
				let result = res.data as PsdResult<R>
				if (result.code == 0 || result.code == 200 || result.code == 2000) {
					let obj  = {
						data: result.content,
						total: result.pagination.total
					} 
					options.success(obj)
				} else if (options.fail) {
					options.fail(result.code, result?.message)
				} else {
					uni.showModal({ content: "请联系管理员，发生系统错误!\n" + result?.message, showCancel: false })
				}
			} else {
				options.fail(res.statusCode, "请联系管理员，发生系统错误!\n statusCode=" + res.errMsg)
			}
		},
		fail: (err) => {
			// uni.showToast({ icon: "none", title: err?.errMsg ?? "未知错误" })
			options.fail(1, JSON.stringify(err))
		}
	})
}